package repositories;

import java.util.Collection;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import domain.Comment;

@Repository
public interface CommentRepository extends JpaRepository<Comment,Integer> {
	
	//Find a comment by a painting id
	@Query("select c from Comment c where c.painting.id = ?1 and c.parent = null")
	Collection<Comment> findCommentParentByPaintingId(int paintingId);

	//Find the comment with more responses
	@Query("select c from Comment c where c.children.size = (select max(cAux.children.size) from Comment cAux)")
	Collection<Comment> findCommentWithMoreResponses();
	
	
}
